package com.example.tokentest2_7_x.webcontroller;

import com.example.tokentest2_7_x.config.component.PassToken;
import com.example.tokentest2_7_x.redispackage.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;

/**
 * \* @author: wky
 * \* Date: 2022/10/09
 * \* Time: 10:12
 * \* To change this template use File | Settings | File Templates.
 * \* Description:如果报以下错误，即需要添加  @ResponseBody 注解加上
 * \* When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on
 * \* the "Access-Control-Allow-Origin" response header.  To allow credentials to a set of origins, list them
 * \* explicitly or consider using "allowedOriginPatterns" instead.
 * \
 */
@RestController
public class LoginController {

    @Autowired
    RedisCache redisCache;

    //@ResponseBody
    @RequestMapping("/userLogin")
    public String userLogin(HttpServletRequest request) {
        System.out.println(request.getHeader("token"));
        redisCache.setCacheObject("token2_7_x","abcdefghijklmnabcdefghijklmn001",5, TimeUnit.MINUTES);
        return redisCache.getCacheObject("token2_7_x");
    }

    //@ResponseBody
    @PassToken
    @RequestMapping("/test1")
    public String test1() {
        return "test1";
    }

    //@ResponseBody
    @RequestMapping("/test2")
    public String test2() {
        return "test2";
    }


}